package com.lwb.ztx.database;

import android.content.Context;

import com.lwb.ztx.database.greendao.dao.DaoMaster;
import com.lwb.ztx.database.greendao.dao.DaoSession;


/**
 * Created by huhaibing on 2015/9/14.
 */
public class GreenDaoManager {
    public static final String DB_NAME = "ztx-db";

    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    public static DaoSession getDaoSession(Context context) {
        return getDaoSession(context,DB_NAME);
    }

    public static DaoMaster getDaoMaster(Context context, String dbName) {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, dbName, null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    public static DaoSession getDaoSession(Context context, String dbName) {
        if (daoSession == null) {
            if (daoMaster == null) {
                daoMaster = getDaoMaster(context, dbName);
            }
            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }


}
